package com.imoblife.brainwavestus.util;

import java.util.Locale;

import com.imoblife.brainwavestus.R;
import com.imoblife.brainwavestus.model.Constant;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class ProductUtil {

	public static void sendEmail(Context context) {

		Intent emailIntent = new Intent(Intent.ACTION_SEND);
		emailIntent.setType("plain/text");
		String subject = " Unable to Restore Google Billing";
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"appandDebugInfo", 0);

		String content = sharedPreferences.getString("debugInfo", "");
		emailIntent.putExtra(Intent.EXTRA_EMAIL,
				new String[] { "Apple@downloadandroid.info", });
		emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
		emailIntent.putExtra(Intent.EXTRA_TEXT, content);
		context.startActivity(emailIntent);
	}

	public static void appandDebugInfo(Context context, String debugInfo) {

		SharedPreferences preferences = context.getSharedPreferences(
				"appandDebugInfo", 0);

		preferences
				.edit()
				.putString("debugInfo",
						preferences.getString("debugInfo", "") + debugInfo)
				.commit();
	}

	public static String getLang() {

		String lv = Locale.getDefault().toString();

		if (lv.equals("ja_JP") || lv.equals("zh_CN") || lv.equals("zh_TW")) {
			return lv;
		}

		return "default";
	}
	
	public static int discount2ImgId(String discount) {
		
		int realDiscount = (int)(Double.parseDouble(discount)*10);
		
		switch (realDiscount) {
		case 6:
			return R.drawable.specail_60;
		case 7:
			return R.drawable.specail_70;
		case 8:
			return R.drawable.specail_80;
		case 9:
			return R.drawable.specail_90;
		default:
			return R.drawable.specail_50;
		}
	}
	
	public static String getTUSGold(String price) {
		String tusPrice = new String(price);
		price = price.replace("$", "");
		price = price.replace(" ", "");

		float tus = 0;

		try {
			tus = Float.parseFloat(price);
		} catch (Exception e) {
			return tusPrice;
		}

		tus *= 10;
		tus += 0.5;

		String tuspoint = "" + ((int) tus);

		return tuspoint;

	}
	
	public static int string2Int(String strings) {
		
		int value = Constant.INT_DOWN_STATE_NOT_ENBLE;
		
		try {
			
			value = Integer.parseInt(strings);
		} catch (NumberFormatException e) {
			
			e.printStackTrace();
		}
		
		return value;
	}
	
	public static String long2String (long value) {
		
		String string = String.valueOf(value);
		
		return string;
	}
	
	public static String downloadStateTransform(int state) {
		
		String stringState = null;
		
		switch(state) {
			
		case Constant.INT_DOWN_STATE_START:
			stringState = Constant.DOWNLOAD_STATE_START;
			break;	
		case Constant.INT_DOWN_STATE_CANCEL:
			stringState = Constant.DOWNLOAD_STATE_CANCEL;
			break;
		case Constant.INT_DOWN_STATE_END:
			stringState = Constant.DOWNLOAD_STATE_END;
			break;
		case Constant.INT_DOWN_STATE_FAILE:
			stringState = Constant.DOWNLOAD_STATE_FAILE;
			break;
		case Constant.INT_DOWN_STATE_NOT_ENBLE:
			stringState = Constant.DOWNLOAD_STATE_NOT_ENBLE;
			break;
		}
		
		return stringState;
	}
}
